/**
 * Created by Administrator on 15-4-2.
 */
var express = require('express');
var router = express.Router();
var ArticleServices = require('../services/Article');

/** -------------------------------------------------------------------------------------
 *  进入技术应用列表页面
 *  -------------------------------------------------------------------------------------
 * */
router.get('/', function (req, res) {
    return res.render('home/services', {});
});

router.get('/list', function (req, res) {

    var page = req.query;

    ArticleServices.list(page, function (err, returnPage) {

        if (err) {
            res.statusCode = 500;
            return res.send({});
        } else {

            res.statusCode = 200;
            return res.send(returnPage);
        }

    });

});

//ajax请求文章内容
router.get('/content/', function (req, res) {

    var _id = req.query._id;
    ArticleServices.findOne(_id, function (err, article) {
        if (err) {
            res.statusCode = 500;
            return res.send({article: null});
        } else {
            res.statusCode = 200;
            return res.send({article: article});
        }


    })
});

router.get('/content/:_id', function (req, res) {

    var _id = req.params._id;
    ArticleServices.findOne(_id, function (err, article) {
        if (err) {
            res.statusCode = 404;
            res.render('404', {});
        } else {
            res.statusCode = 200;
            res.render('home/article', {article: article});
        }

    })
});
module.exports = router;
